<template>
	<view class="container">
		<view class="form-box">
			<view class="form-item">
				<view class="item-label">旧密码</view>
				<view class="item-input">
					<input v-model="formData.password" placeholder-class="input-placeholder" placeholder="请输入旧密码" />
				</view>
			</view>
			<view class="form-item">
				<view class="item-label">新密码</view>
				<view class="item-input">
					<input v-model="formData.newPassword" placeholder-class="input-placeholder" placeholder="请输入旧密码" />
				</view>
			</view>
			<view class="form-item">
				<view class="item-label">确认新密码</view>
				<view class="item-input">
					<input v-model="formData.confirmPassword" placeholder-class="input-placeholder" placeholder="请输入旧密码" />
				</view>
			</view>
		</view>
		<view class="submit-btn" @tap="doSubmit">确认</view>
	</view>
</template>

<script>
	import { http, showToastMsg } from '../../utils'
	
	export default {
		data() {
			return {
				formData: {
					password: '',
					newPassword: '',
					confirmPassword: ''
				}
			}
		},
		
		methods: {
			
			doSubmit() {
				const that = this
				let d = that.formData
				
				if (d.password.length <= 0) {
					return showToastMsg('请输入旧密码')
				}
				if (d.newPassword.length <= 0) {
					return showToastMsg('请输入新密码')
				}
				if (d.newPassword.length < 6) {
					return showToastMsg('新密码至少6位')
				}
				if (d.confirmPassword.length <= 0) {
					return showToastMsg('请再次输入新密码')
				}
				if (d.newPassword != d.confirmPassword) {
					return showToastMsg('请两次密码输入不一致')
				}
				
				http('/user/modifypassword', d, {loadingTitle: '正在修改'}).then(res => {
					if (res.code == 20000) {
						that.formData.password = ''
						that.formData.newPassword = ''
						that.formData.confirmPassword = ''
						return showToastMsg('修改成功')
					}
				})
			}
			
		}
	}
</script>

<style>
	.container {
		width: 750rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
	}
	
	.form-box {
		width: 620rpx;
		margin-top: 20rpx;
	}
	
	.form-item {
		width: 100%;
		margin-top: 50rpx;
	}
	
	.item-label {
		color: #666666;
		font-size: 24rpx;
		margin-left: 34rpx;
	}
	
	.input-placeholder {
		color: #999999;
		font-size: 26rpx;
	}
	
	.item-input {
		width: 100%;
		height: 88rpx;
		background-color: #f8f8f8;
		border-radius: 44rpx;
		display: flex;
		flex-direction: row;
		align-items: center;
		margin-top: 18rpx;
	}
	
	.item-input input {
		color: #333333;
		font-size: 26rpx;
		margin-left: 34rpx;
	}
	
	.submit-btn {
		width: 556rpx;
		height: 92rpx;
		color: #ffffff;
		font-size: 36rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		background-color: #45d6b7;
		border-radius: 46rpx;
		position: fixed;
		bottom: 60rpx;
	}
</style>
